package cn.com.mr01.lianxi.mr_lianxi_04;

import java.io.IOException;
import java.util.Iterator;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

public class IntSumReducer extends
		Reducer<Text, IntWritable, Text, IntWritable> {

	IntWritable s = new IntWritable();

	@Override
	protected void reduce(Text key, Iterable<IntWritable> values,
			Context context) throws IOException, InterruptedException {

		Iterator<IntWritable> it = values.iterator();
		// 记录总条数
		int count = 0;
		while (it.hasNext()) {
			IntWritable value = it.next();
			count = count + value.get();
		}
		s.set(count);
		// 3. 输出
		context.write(key, s);
	}
}
